import "crvpuppet"

define at3_ganglia_daemon($webaddr="", $roleid="") {
  if $AutoMode==true and $CloudCRV==true {
    $gangliasrvaddr=get_provider_attr($webaddr,$roleid,"GangliaSrvAddr")
  }
  
  if ( $AutoMode == false ) or ( $AutoMode==true and $CloudCRV==true ) {

    notice ("gangliasrvaddr=$gangliasrvaddr")
    
    package { ["ganglia", "ganglia-gmond"]:
      ensure => installed,
    }
    
    file { "/etc/gmond.conf":
      owner => "root",
      group => "root",
      mode => 644,
      content => template("at3_ganglia_daemon/etc-gmond.conf.tpl"),
      notify => Service["gmond"],
    }

    service { [ "gmond"]:
      ensure => running,
      enable => true,
      hasstatus => true,
      hasrestart => true,
      require => [Package["ganglia", "ganglia-gmond"], File["/etc/gmond.conf"]]
    }

  }

  if $AutoMode==true and $CloudCRV==true {
    set_role_attr($webaddr,$roleid,"GangliaClientAddr","$ipaddress")    
    #set_role_attr($webaddr,$roleid,"ProfileApplied","True")
  }
}

define at3_ganglia_daemon_reverse($webaddr, $roleid) {
  #set_role_attr($webaddr,$roleid,"ReverseProfileApplied","True")
}

